home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-10-15 | 12.5 KB | 406 lines | [TEXT/MPS ] |
- #
- # File: DrawShapes.vu
- #
- # Contains: A test script for DrawShapesVU, the MacApp DrawShapes example program which
- # has been built with the Assistance Module for MacApp. The script selects
- # a random shape to draw, draws it to a random size in a random location within
- # the window, colors and shades it randomly, and then moves it to a random location in
- # the window. It selects a random editing operation after every "shapesPerEdit"
- # shapes are drawn. A number of shapes equal to the global variable "numShapes"
- # (set to a default of 15) is drawn before the script stops.
- #
- # DrawShapesVU can run critically low on memory if the partition size is too
- # small. DrawShapesVU may not have enough memory to even exit in these cases.
- # Because of this, this script will simply detect the situation and abort the
- # script.
- #
- # The theRandomSeed script parameter specifies the variable used to seed Virtual
- # User's random number generator. By using the same theRandomSeed variable on
- # the same setup, this script has the ability to play back its actions at a future
- # time.
- #
- #
- # Requirements: In order for the script to run properly, the target should have the
- # DrawShapesVU MacApp demo program version 1.0d1 either all ready running
- # or able to be located by System 7 Finder's "Find" command. Versions of
- # DrawShapes that have not been built with the MacApp assistance module will
- # not work properly. For best results use the version included in the
- # Virtual User 2.0 package.
- #
- #
- # Written by: Jim Schneider
- #
- # Copyright: © 1990-1992 by Apple Computer, Inc., all rights reserved.
- #
- # Change History:
- #
- # 8/14/92 DGG RandomSeed added.
- # 8/13/92 DGG "retrace" script building removed in prep. for RandomSeed
- # DSOutOfMemory check added.
- # 7/7/92 DGG cleanup for Virtual User 2.0
- # 8/15/90 JAS added echo option to build "retrace" script as output
- # 8/15/90 JAS took out window scrolling, inserted window drag to known location
- # 5/15/90 JAS take out infinite loop.
- # 5/2/90 JAS creation
- #
-
- Libraries "UtilityTasks.vulib";
-
- (************************************************************************************
- * Task SelectPalletteTool()
- * Select the DrawShapes tool from the pallette
- ************************************************************************************)
- task SelectPalletteTool(theTool)
- begin
- global gWindGRect;
-
- x:=gWindGRect[1]-20;
- y:=gWindGRect[2]+20+(40*(theTool-1));
- move a: {x,y};
- click;
- end;
-
-
- (************************************************************************************
- * Task HandleColorPicker()
- * Pick a random color from the color picker dialog.
- ************************************************************************************)
- task HandleColorPicker()
- begin
- global gMaxScrollValue;
- global gRelColorPickerCenter;
- global gPickerRadius;
-
- match[window o:1 r:?colorPickerWingRect];
- #scrollValue := random(1,gMaxScrollValue);
- #scroll [scrollBar w:[window o:1]] a:{scrollValue,gMaxScrollValue};
- wait(1);
- colorPickerCenter := {gRelColorPickerCenter[1] + colorPickerWingRect[1],gRelColorPickerCenter[2] + colorPickerWingRect[2]};
- x_offset := random(0,(gPickerRadius*2)) - gPickerRadius;
- y_offset := random(0,(gPickerRadius*2)) - gPickerRadius;
- while ((x_offset*x_offset) + (y_offset*y_offset) > gPickerRadius*gPickerRadius)
- begin
- x_offset := random(0,(gPickerRadius*2)) - gPickerRadius;
- y_offset := random(0,(gPickerRadius*2)) - gPickerRadius;
- end;
- x:=colorPickerCenter[1]+x_offset;
- y:=colorPickerCenter[2]+y_offset;
- move a:{x,y};
- wait(1);
- click;
- select [button t:'OK' w:[window o:1]]!;
- end;
-
-
- (************************************************************************************
- * Task ColorShape()
- * Color the selected shape a random color from Colors menu. Screen out the '---'
- * item.
- ************************************************************************************)
- task ColorShape()
- begin
- global gNumColors;
- global gColorSepItem;
- global gPickColorItem;
-
- theColor := random(1,gNumColors);
- if (theColor = gColorSepItem)
- while (theColor = gColorSepItem)
- theColor := random(1,gNumColors);
- select [menuitem m:[menu t:"Colors"] o:theColor];
- if (theColor = gPickColorItem)
- HandleColorPicker();
- end;
-
- (************************************************************************************
- * Task ShadeShape()
- * Shade the selected shape a random shade from the Shades menu.
- ************************************************************************************)
- task ShadeShape()
- begin
- global gShadeMenuPosn;
- global gShadeCellSize;
-
- theRow := random(1,2);
- theColumn := random(0,2);
- x:=gShadeMenuPosn[1];
- y:=gShadeMenuPosn[2];
- move a:{x,y};
- pressMouse;
- wait(1);
- x:=gShadeCellSize*theColumn;
- y:=gShadeCellSize*theRow;
- move r: {x,y};
- wait(1);
- releaseMouse;
- end;
-
-
- (************************************************************************************
- * Task TestShapeDrawn()
- * Return true if a shape was just drawn (we know this by seeing if the 'Colors'
- * menu is enabled). Otherwise, return false.
- ************************************************************************************)
- task TestShapeDrawn()
- begin
- match[menu t:'Colors' e:?enabled]!;
- return(enabled);
- end;
-
-
- (************************************************************************************
- * Task DrawShape()
- * Select a random shape to draw from pallette and draw it at a random position.
- * Size it to a random size. Return the coordinates of the shape's Rectangle.
- ************************************************************************************)
- task DrawShape()
- begin
- global gRect;
- global gOval;
- global gThickGRect;
- global gWindGRect;
-
- prevSpeed := mouseSpeed(4);
- theTool := random(gRect,gThickGRect);
- SelectPalletteTool(theTool);
- xCoord1 := random(gWindGRect[1],gWindGRect[3]);
- yCoord1 := random(gWindGRect[2],gWindGRect[4]);
- move a: {xCoord1,yCoord1};
- wait(1);
- pressMouse;
- xCoord2 := random(gWindGRect[1],gWindGRect[3]);
- yCoord2 := random(gWindGRect[2],gWindGRect[4]);
- move a: {xCoord2,yCoord2};
- wait(1);
- releaseMouse;
- mouseSpeed(prevSpeed);
- return({xCoord1,yCoord1,xCoord2,yCoord2});
- end;
-
-
- (************************************************************************************
- * Task MoveShape()
- * Move the most current shape to a random position. Pass back new shape gRectangle.
- ************************************************************************************)
- task MoveShape()
- begin
- global gArrow;
- global gWindGRect;
- global gShapegRect;
-
- xCoord := random(gWindGRect[1],gWindGRect[3]);
- yCoord := random(gWindGRect[2],gWindGRect[4]);
- SelectPalletteTool(gArrow);
- x:=(gShapegRect[1]+gShapegRect[3])/2;
- y:=(gShapegRect[2]+gShapegRect[4])/2;
- move a: {x,y};
- pressMouse;
- wait(1);
- move a: {xCoord,yCoord};
- wait(1);
- releaseMouse;
- shapeWidth := gShapegRect[3]-gShapegRect[1];
- shape_height := gShapegRect[4] - gShapegRect[2];
- return({xCoord-(shapeWidth/2),yCoord-(shape_height/2),xCoord+(shapeWidth/2),yCoord+(Shape_height/2)});
- end;
-
-
- (************************************************************************************
- * Task DoSomeEditing()
- * Select random item from edit menu and then possibly do something else, depending
- * on what item was selected. Screen out the "---" items.
- ************************************************************************************)
- task DoSomeEditing()
- begin
- global gShapegRect;
- global gArrow;
- global gNumEditItems;
- global gUndoItem;
- global gEditSepItem1;
- global gCutItem;
- global gCopyItem;
- global gPasteItem;
- global gClearItem;
- global gSelectAllItem;
- global gEditSepItem2;
- global gShowClipboardItem;
-
- theItem := random(1,gNumEditItems);
- while (not ((theItem = gEditSepItem1) or (theItem = gEditSepItem2)))
- theItem := random(1,gNumEditItems);
- match [menuitem m:[menu t:'Edit'] o:theItem e:?enabled];
- while (not enabled)
- begin
- theItem := random(1,gNumEditItems);
- match [menuitem m:[menu t:'Edit'] o:theItem e:?enabled];
- end;
- select [menuitem m:[menu t:'Edit'] o:theItem]!;
- if ((theItem = gCutItem) or (theItem = gCopyItem))
- begin
- select [menuitem t:'Paste' m:[menu t:'Edit']]!;
- end;
- else if (theItem = gSelectAllItem)
- begin # move everything 50 pixels right or left, up or down
- xCoord := 50 - random(1,100);
- yCoord := 50 - random(1,100);
- SelectPalletteTool(gArrow);
- x := (gShapegRect[1]+gShapegRect[3])/2;
- y := (gShapegRect[2]+gShapegRect[4])/2;
- move a: {x,y};
- pressMouse;
- wait(1);
- move r: {xCoord,yCoord};
- wait(1);
- releaseMouse;
- end;
- else if (theItem = gShowClipboardItem)
- begin
- wait(1);
- close [window o:1];
- end;
- end;
-
-
- (************************************************************************************
- * Task CleanUpWindow()
- * Clean up the DrawShapes window
- ************************************************************************************)
- task CleanUpWindow()
- begin
-
- match [menuitem t:"Select All" m:[menu t:"Edit"] e:?enabled];
- if (enabled)
- begin
- select[menuitem t:"Select All" m:[menu t:"Edit"]];
- select[menuitem t:"Clear" m:[menu t:"Edit"]];
- end;
- end;
-
-
- (************************************************************************************
- * Task GetWindCntgRect()
- * Get the gRectangle representing the DrawShape's window content region
- ************************************************************************************)
- task GetWindCntgRect()
- begin
- global gPixLeft;
- global gPixTop;
- global gPixRight;
- global gPixBottom;
-
- match [window o:1 r:?windowGRect]!;
- return({windowGRect[1]+gPixLeft,windowGRect[2]+gPixTop,windowGRect[3]-gPixRight,windowGRect[4]-gPixBottom});
- end;
-
- (************************************************************************************
- * Task DSOutOfMemory()
- * Test to see if an out of memory dialog is present.
- ************************************************************************************)
- task DSOutOfMemory()
- begin
- if match [window s:dialog o:1]
- begin
- if (match [icon t:'' o:3 e:false]) or
- (match [staticText t:'Memory space is low. Some commands may be disabled.'])
- begin
- return true;
- end;
- end;
- else
- return false;
- end;
-
- ##### MAIN EXECUTION STARTS HERE ######
- (************************************************************************************
- * The variable numShapes determines number of shapes drawn.
- * ShapesPerEdit determines the number of shapes to draw before a random editing
- * operation takes place.
- * The theRandomSeed parameter specifies the variable to seed the random number
- * generator. By using the same theRandomSeed variable on the same setup, this
- * script has the ability to play back its actions at a future time.
- ************************************************************************************)
- script DrawShapesMain(numShapes := 15, shapesPerEdit := 3, theRandomSeed := undefined)
- begin
- # set up the random seed process
- if IsUndefined(theRandomSeed)
- theRandomSeed := Random();
- RandomSeed(theRandomSeed);
- println "### DrawShapesVU Random Seed: ",theRandomSeed;
-
- if (not LaunchApp("DrawShapesVU"))
- begin
- println "### Unable to launch DrawShapesVU!!!∂n### Script aborting!";
- exit;
- end;
-
- # indices into pallette
- gArrow := 1;
- gRect := 2;
- gOval := 3;
- gThickGRect := 4;
-
- # misc. globals
- gColorSepItem := 8;
- gPickColorItem := 9;
- gMaxScrollValue := 32767;
- gRelColorPickerCenter := {293,137};
- gPickerRadius := 100;
- gShadeMenuPosn := {125,10};
- gShadeCellSize := 25;
-
- # pixels between window gRect and content gRect
- gPixTop := 21;
- gPixLeft := 41;
- gPixBottom := 17;
- gPixRight := 17;
-
- #edit menu items
- gNumEditItems := 9;
- gUndoItem := 1;
- gEditSepItem1 := 2;
- gCutItem := 3;
- gCopyItem := 4;
- gPasteItem := 5;
- gClearItem := 6;
- gSelectAllItem := 7;
- gEditSepItem2 := 8;
- gShowClipboardItem := 9;
-
- match [menu t:"Colors" i:?itemList]!;
- gNumColors := card(itemList); # get number of items in Colors menu
-
- match [menu t:"edit" i:?itemList]!;
- gNumEditItems := card(itemList); # get number of items in Edit menu;
-
- CloseAllWindows();
- select [menuItem t:"New" m:"File"];
- CleanUpWindow();
-
- # this is done to ensure that absolute moves in output script will match those
- # made in running this script
- println "### Now performing DrawShapesVU Stress Test!";
- drag [window o:1] a:{5,25};
-
- gWindGRect := GetWindCntgRect(); # get window's content gRectangle
-
- for i := 1 to numShapes
- begin
- if DSOutOfMemory()
- begin
- println "### DrawShapesVU is critically out of memory!";
- println "### Aborting script!";
- exit;
- end;
-
- gShapegRect := DrawShape();
- if TestShapeDrawn()
- begin
- ColorShape();
- ShadeShape();
- gShapegRect := MoveShape();
- if ((i mod shapesPerEdit) = 0)
- DoSomeEditing();
- end;
- end;
-
- end; # DrawShapesStress.vu